package com.easy.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.Filter;
import java.io.IOException;

/**
 * @ClassName LoginFilter
 * @Description TODO 登录过滤器
 * @Author 周轩霆
 * @Date 2022/5/28 14:53
 **/
@WebFilter(urlPatterns = {"/staff/*"})
public class LoginFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("-------Filter");
        HttpServletRequest req = (HttpServletRequest) request;
        HttpSession session = req.getSession();
        Object obj = session.getAttribute("LOGINSTAFF");
        if (obj != null) {
            //通过过滤器检查，到下一个过滤器或者资源
            chain.doFilter(request, response);
        } else {
           // response.getWriter().write("nologin");

        }

    }
}
